<?php
include('../resource/db/db.php');
if (!isset($_COOKIE['user_id'])) {
    header("Location: ../main/login.php");
    exit();
}
$user_id = $_COOKIE['user_id'];

$box_number = $_GET['box_number'];

$sql = "SELECT MIN(record_id) as record_id FROM study_records WHERE user_id='$user_id' AND box_number='$box_number' AND is_deleted=FALSE";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    echo $row['record_id'];
} else {
    echo 0;
}
$conn->close();

?>